********************************************************************************
******************************* VARIABLE CREATION ******************************
************************************* for **************************************
****************************** A FIELD OF HER OWN ******************************
********************************************************************************

clear all
estimates clear
set maxvar 20000


************* Recode Other Variables for Education ***************

use "$raw/LandRight_Household_fullsample_clean.dta", clear

replace hhchar_edu_high_1=11 if hhchar_edu_high_spec_1=="ဘုန်းကြီးကျောင်း"
label define hhchar_edu_high_1 11 "Monastic Education", add
replace hhchar_edu_high_2=11 if hhchar_edu_high_spec_2=="ဘုန်းတော်ကြီးကျောင်းပညာရေး"
label values hhchar_edu_high_2 hhchar_edu_high_1

******************************************************************
// label vars
lab var individual_id "Individual ID"
lab var land_yn "Household Uses or Rents Land for Agriculture"

// create variable for respondent age
gen age=hhchar_age_1 if male==1
replace age=hhchar_age_2 if male==0
label var age "Age of Respondent"

// create education variable
gen educ=hhchar_edu_high_1 if male==1
replace educ=hhchar_edu_high_2 if male==0
// creating education categories
gen educode=educ
recode educode (9 10=1) (3 11=2) (4/8=3)
label define educode 1 "Less than Primary" 2 "At least Primary but Less than Secondary" 3 "At least Secondary"
label values educode educode
lab var educode "Highest Level of Education Received by Respondent"
// create separate dummy variables
gen educ1=0
replace educ1=1 if educode==1
lab var educ1 "Respondent has Less than Primary Education"
lab define yesno 1 "Yes" 0 "No"
lab val educ1 yesno
gen educ2=0
replace educ2=1 if educode==2
lab var educ2 "Respondent has at least Primary but Less than Secondary Education"
lab val educ2 yesno
gen educ3=0
replace educ3=1 if educode==3
lab var educ3 "Respondent has at least Secondary Education"
lab val educ3 yesno

// create family size variable
gen hh_size=hh_member_num
lab var hh_size "Number of Household Members"

// create total landsize variable
***LI Mar 2021: maxine has corrected the units so that all land is now in acres, so making a note of that
forval i=1/9 {
replace landuse_area_unit_`i'=2 if landuse_area_unit_`i'==1|landuse_area_unit_`i'==3
}

gen landsize=0
gen nplot=0
forval i=1/9{
	replace landsize=landsize+landuse_area_`i' if !mi(landuse_area_`i')
	replace nplot= nplot + 1 if !mi(landuse_area_`i')
}

replace nplot=. if land_yn==0
replace nplot=. if nplot==0
lab var landsize "Total Land Holding Size (Acres)"
lab var nplot "Number of plots with nonmissing plot size"

gen landsize_avg=landsize/nplot

***there are 8 women who report zero plots and landsizes even though land_yn==1 & 6 men
***making a code for those hh where both men and women report positive landsizes and plots

gen cman=nplot>0 & !mi(nplot) & male==1
gen cwom=nplot>0 & !mi(nplot) & male==0
egen cman1=max(cman), by(hhid)
egen cwom1=max(cwom), by(hhid)
gen bothreportland=1 if cman1==1 & cwom1==1
replace bothreportland=. if land_yn==0
gen onlymanreportland=1 if cman1==1 & cwom1==0
gen onlywomreportland=1 if cman1==0 & cwom1==1
drop cman* cwom*

***there are 1657 hh where both the man and the woman report non-zero amounts of land: this is going to be our main sample for analysis
lab var bothreportland "Both partners report nonmissing land value"
lab var onlymanreportland "Man reports non-zero land, woman reports zero"
lab var onlywomreportland "Woman reports non-zero land, man reports zero"

// create landholding categorical variable
gen land_cat=0 if landsize==0|landsize==.
replace land_cat=1 if landsize>0 & landsize<=1
replace land_cat=2 if landsize>1 & landsize<=5
replace land_cat=3 if landsize>5 & landsize<=10
replace land_cat=4 if landsize>10 & landsize<=15
replace land_cat=5 if landsize>15 & !mi(landsize)
label define land_cat 0 "No Land" 1 "0 < Acre <= 1" 2 "1 < Acre <= 5" 3 "5 < Acre <= 10" 4 "10 < Acre <= 15" 5 "15 < Acre"
label values land_cat land_cat
lab var land_cat "Total Land Holding Size (Cat.)"

/****FORM 7 VARIABLES****/
// create dummy variable for hh with any plot with a form 7
gen form7_any=0
forvalues i=1/9{
	replace form7_any=1 if landuse_doc_type_5_`i'==1
}
replace form7_any=.d if land_yn==.d
replace form7_any=.n if land_yn==0
lab var form7_any "Household has at least one Form 7"
lab val form7_any yesno

// create variable for number of plots with a Form 7
gen form7_num=0
gen dk_form7num = 0
forvalues i=1/9{
	replace form7_num=form7_num+1 if landuse_doc_type_5_`i'==1
	replace dk_form7num=dk_form7num + 1 if (form7num_`i'==.|form7num_`i'==.d) & landuse_area_`i'~=. & landuse_area_`i'~=.d
}
replace form7_num=.d if land_yn==.d
replace form7_num=.n if land_yn==0
lab var form7_num "Number of Plots with at least one Form 7"
replace dk_form7num=dk_form7num/nplot
lab var dk_form7num "Fraction of plot for which #form 7 is not known"


// total # of form 7s in household
egen form7_tot=rowtotal(form7num_?), missing
replace form7_tot=.d if form7_any==.d | form7_num==.d
replace form7_tot=.n if form7_any==0 | form7_any==.n
lab var form7_tot "Total number of Form 7's in hh"


*****FEMALE NAMES ON FORM 7

// create dummy variable for female name on any form 7
// create dummy variable for female name exclusively on any form 7
// create dummy variable for female name exclusively on any form 7 and no male name on any other form 7 for that plot
forvalues i=1/14{
	gen male_`i'=.
	gen female_`i'=.
	replace female_`i'=hhchar_relation_`i' if hhchar_sex_`i'==0
	replace male_`i'=hhchar_relation_`i' if hhchar_sex_`i'==1
}
gen form7_fem=0
forvalues i=1/9{
	gen form7_fem_`i'=0
	forvalues j=1/17{
		gen form7_fem_`i'_`j'=0
		forvalues k=1/21{
			forvalues l=1/14{
				replace form7_fem_`i'_`j'=1 if form7_name_`k'_`i'_`j'=="1" & female_`l'==`k'
			}
		}
		replace form7_fem_`i'=1 if form7_fem_`i'_`j'==1
	}
	replace form7_fem=1 if form7_fem_`i'==1
}
replace form7_fem=.d if land_yn==.d
replace form7_fem=.n if land_yn==0
lab var form7_fem "Household has at least 1 Form 7 with Female Name (joint)"
lab val form7_fem yesno

// create dummy variable for female HoH name on any form 7
// create dummy variable for female HoH name exclusively on any form 7
// create dummy variable for female HoH name exclusively on any form 7 and no male name on any other form 7 for that plot
gen form7_femhoh=0
gen form7_femhoh_excl=0
gen form7_femhoh_nomale=.
forvalues i=1/9{
	gen form7_femhoh_nomale_plot_`i'=.
	forvalues j=1/17{
		forvalues k=1/21{
			if `k'!=1{
				replace form7_femhoh=1 if form7_name_1_`i'_`j'=="1" & form7_name_`k'_`i'_`j'=="1" & male==0
			}
			if `k'!=2{
				replace form7_femhoh=1 if form7_name_2_`i'_`j'=="1" & form7_name_`k'_`i'_`j'=="1" & male==1
			}
		}
		replace form7_femhoh_excl=1 if form7_name_`i'_`j'=="1" & male==0
		replace form7_femhoh_excl=1 if form7_name_`i'_`j'=="2" & male==1
		replace form7_femhoh_nomale_plot_`i'=1 if form7_name_`i'_`j'=="1" & mi(form7_femhoh_nomale_plot_`i') & male==0
		replace form7_femhoh_nomale_plot_`i'=1 if form7_name_`i'_`j'=="2" & mi(form7_femhoh_nomale_plot_`i') & male==1
		replace form7_femhoh_nomale_plot_`i'=0 if form7_name_2_`i'_`j'=="1" & male==0
		replace form7_femhoh_nomale_plot_`i'=0 if form7_name_1_`i'_`j'=="1" & male==1
	}
	replace form7_femhoh_nomale_plot_`i'=0 if mi(form7_femhoh_nomale_plot_`i')
	replace form7_femhoh_nomale=1 if form7_femhoh_nomale_plot_`i'==1
}
replace form7_femhoh_nomale=0 if mi(form7_femhoh_nomale)
replace form7_femhoh=1 if form7_femhoh_excl==1
replace form7_femhoh=.d if land_yn==.d
replace form7_femhoh=.n if land_yn==0
replace form7_femhoh_nomale=.d if land_yn==.d
replace form7_femhoh_nomale=.n if land_yn==0
lab var form7_femhoh "Household has at least 1 Form 7 in Female HoH's name (joint)"
lab var form7_femhoh_nomale "HH has at least 1 Form 7 in Female HoH's name (excl. and no other male)"
lab val form7_femhoh form7_femhoh_nomale yesno


******LOAN VARIABLES

// create variable for number of loans in household
gen loan_num=0
forvalues i=1/9{
    replace loan_num=loan_num+1 if coll_used_`i'==1
}
lab var loan_num "Total Number of Loans in Household (Land Collateralized)"


* create dummy variables for select multiple variable
forvalues i=1/2{
	split coll_relation_`i', gen(coll_relation_t_`i'_)
	unab vars_`i': coll_relation_t_`i'_?
	local count_`i'=`: word count `vars_`i'''
	forvalues j=1/21{
		gen coll_relation_`j'_`i'=0
		forvalues k=1/`count_`i''{
			replace coll_relation_`j'_`i'=1 if coll_relation_t_`i'_`k'=="`j'"
			replace coll_relation_`j'_`i'=. if coll_relation_`i'=="."
			order coll_relation_`j'_`i', before(coll_used_num_`i')
		}
	}
}
drop coll_relation_t_*

// create variable for number of loans in female head of household's name
gen loan_num_fem=0
forvalues i=1/2{
	replace loan_num_fem=loan_num_fem+1 if (coll_relation_1_`i'==1 & male==0) | (coll_relation_2_`i'==1 & male==1)
}
forvalues i=3/9{
	replace loan_num_fem=loan_num_fem+1 if (coll_relation_`i'==1 & male==0) | (coll_relation_`i'==2 & male==1)
}
lab var loan_num_fem "Number of Loans in Female HoH's Name (Land Collateralized)"


// create variable for number of loans in male head of household's name
gen loan_num_male=0
forvalues i=1/2{
	replace loan_num_male=loan_num_male+1 if (coll_relation_1_`i'==1 & male==1) | (coll_relation_2_`i'==1 & male==0)
}
forvalues i=3/9{
	replace loan_num_male=loan_num_male+1 if (coll_relation_`i'==1 & male==1) | (coll_relation_`i'==2 & male==0)
}
lab var loan_num_male "Number of Loans in Male HoH's Name (Land Collateralized)"


// create variable for total ag income from plots with a female name on the form 7
gen aginc_fem=.
forvalues i=1/9{
	forvalues j=1/6{
		replace aginc_fem=0 if !mi(agrioutput_vsold_`i'_`j') & form7_fem_`i'==1 & mi(aginc_fem)
		replace aginc_fem=aginc_fem+agrioutput_vsold_`i'_`j' if !mi(agrioutput_vsold_`i'_`j') & form7_fem_`i'==1
	}
}
replace aginc_fem=0 if mi(aginc_fem)
lab var aginc_fem "Total Agricultural Revenue from Plots with Female Name on Form 7"
replace aginc_fem=.d if form7_fem==.d
replace aginc_fem=.n if form7_fem==.n | form7_fem==0
* create ln variable (+1 to avoid problem with log 0)
gen aginc_fem_ln=ln(aginc_fem+1)
replace aginc_fem_ln=.d if aginc_fem==.d
replace aginc_fem_ln=.n if aginc_fem==.n
lab var aginc_fem_ln "Log of Total Agricultural Revenue from Plots with Female Name on Form 7"


// create variable for rice income from paddy plots with a female name on the form 7
gen riceinc_fem=.
forvalues i=1/9{
	forvalues j=1/6{
		replace riceinc_fem=0 if !mi(agrioutput_vsold_`i'_`j') & form7_fem_`i'==1 & mi(riceinc_fem) & agri_crop_label_`i'_`j'==1
		replace riceinc_fem=riceinc_fem+agrioutput_vsold_`i'_`j' if !mi(agrioutput_vsold_`i'_`j') & form7_fem_`i'==1 & agri_crop_label_`i'_`j'==1
	}
}
replace riceinc_fem=0 if mi(riceinc_fem)
lab var riceinc_fem "Total Paddy Revenue from Plots with Female Name on Form 7"
replace riceinc_fem=.d if form7_fem==.d
replace riceinc_fem=.n if form7_fem==.n | form7_fem==0
* create ln variable (+1 to avoid problem with log 0)
gen riceinc_fem_ln=ln(riceinc_fem+1)
replace riceinc_fem_ln=.d if riceinc_fem==.d
replace riceinc_fem_ln=.n if riceinc_fem==.n
lab var riceinc_fem_ln "Log of Total Revenue from Paddy Plots with Female Name on Form 7"


// create variable for total ag income from all plots
gen aginc=.
forvalues i=1/9{
	forvalues j=1/6{
		replace aginc=0 if !mi(agrioutput_vsold_`i'_`j') & mi(aginc)
		replace aginc=aginc+agrioutput_vsold_`i'_`j' if !mi(agrioutput_vsold_`i'_`j')
	}
}
replace aginc=0 if mi(aginc)
lab var aginc "Total Agricultural Revenue from all Plots"
replace aginc=.d if land_yn==.d
replace aginc=.n if land_yn==0


// create variable for total rice income from all paddy plots
gen riceinc=.
forvalues i=1/9{
	forvalues j=1/6{
		replace riceinc=0 if !mi(agrioutput_vsold_`i'_`j') & mi(riceinc) & agri_crop_label_`i'_`j'==1
		replace riceinc=riceinc+agrioutput_vsold_`i'_`j' if !mi(agrioutput_vsold_`i'_`j') & agri_crop_label_`i'_`j'==1
	}
}
replace riceinc=0 if mi(riceinc)
lab var riceinc "Total Agricultural Revenue from all Paddy Plots"
replace riceinc=.d if land_yn==.d
replace riceinc=.n if land_yn==0


// create variable for non ag income accruing to female HoH
gen nonaginc_fem=.
forvalues i=1/6{
	replace nonaginc_fem=0 if (!mi(hhchar_incomeamt_`i') & hh_income_cal_`i'!="စိုက်​ပျိုး​ရေး​နှင့် ​မွေး​မြူ​ရေး​လုပ်​ငန်း​များ" & hhchar_incomesource_mm_1_`i'=="1" & male==0 & mi(nonaginc_fem)) | ///
		(!mi(hhchar_incomeamt_`i') & hh_income_cal_`i'!="စိုက်​ပျိုး​ရေး​နှင့် ​မွေး​မြူ​ရေး​လုပ်​ငန်း​များ" & hhchar_incomesource_mm_2_`i'=="1" & male==1 & mi(nonaginc_fem))
	replace nonaginc_fem=nonaginc_fem+hhchar_incomeamt_`i' if (!mi(hhchar_incomeamt_`i') & hh_income_cal_`i'!="စိုက်​ပျိုး​ရေး​နှင့် ​မွေး​မြူ​ရေး​လုပ်​ငန်း​များ" & hhchar_incomesource_mm_1_`i'=="1" & ///
		male==0) | (!mi(hhchar_incomeamt_`i') & hh_income_cal_`i'!="စိုက်​ပျိုး​ရေး​နှင့် ​မွေး​မြူ​ရေး​လုပ်​ငန်း​များ" & hhchar_incomesource_mm_2_`i'=="1" & male==1)
}
replace nonaginc_fem=0 if mi(nonaginc_fem)
lab var nonaginc_fem "Total non-Agricultural Income from Female HoH"
* create ln variable (+1 to avoid problem with log 0)
gen nonaginc_fem_ln=ln(nonaginc_fem+1)
lab var nonaginc_fem_ln "Log of Total non-Agricultural Income from Female HoH"

// create female agency variables for agricultural decisions
local agency_ag_land "Agricultural farming: selling, renting and buying land"
local agency_ag_stock "Livestock raising (i.e. time of buying and selling)"
local agency_ag_gard "Gardening (i.e. choosing crops, planting, deciding how to use the income from gardening)"
local agency_ag_labor "Agricultural farming: hiring labor"
local agency_ag_crops "Agricultural farming: planting decision (i.e. crops choosing)"
# delimit ;
local agency_ag
	agency_ag_land
	agency_ag_stock
	agency_ag_gard
	agency_ag_labor
	agency_ag_crops;
# delimit cr
foreach var in `agency_ag' {
	gen `var'=0
	forvalues j=1/13{
		replace `var'=1 if agency_activity_calc_`j'=="``var''" & (inlist(agency_decider_`j', 1, 2) & male==0) 
		replace `var'=1 if agency_activity_calc_`j'=="``var''" & (inlist(agency_decider_`j', 2) & male==1)|((inlist(agency_decider_`j', 3) & agency_member_2_`j'=="1" & male==1))
	}
}
lab var agency_ag_land "Female HoH Involved in Decisions About Selling/Renting/Buying Land"
lab var agency_ag_stock "Female HoH Involved in Decisions About Livestock Raising"
lab var agency_ag_gard "Female HoH Involved in Decisions About Gardening"
lab var agency_ag_labor "Female HoH Involved in Decisions About Hiring Agricultural Labor"
lab var agency_ag_crops "Female HoH Involved in Decisions About Choosing Crops"

// create first index for female agency over agricultural decisions 
// LAKSHMI MAR 2021: (take sum and then standardize WRT full sample mean so that men and women reports are on same scale)
egen agency_ag_index1=rowtotal(`agency_ag')
summ agency_ag_index1
local mean_ag=r(mean)
local sd_ag=r(sd)
gen agency_ag_index11=(agency_ag_index1-`mean_ag')/`sd_ag' 

lab var agency_ag_index11 "Index of Female Agency in Agricultural Decisions (Standardized Sum)"
lab var agency_ag_index1 "Index of Female Agency in Agricultural Decisions (0-5)"


// create female agency variables for expenditure decisions
local agency_exp_childcare "Child care"
local agency_exp_health "Healthcare"
local agency_exp_cook "Cooking"
local agency_exp_educ "Expenditure for children education"
local agency_exp_childoth "Other expenditure for children"
local agency_exp_food "Expenditure for household's food consumption"
local agency_exp_rel "Religious expenditure (i.e. donation)"
local agency_exp_fert "Fertility decisions"
# delimit ;
local agency_exp
	agency_exp_childcare
	agency_exp_health
	agency_exp_cook
	agency_exp_educ
	agency_exp_childoth
	agency_exp_food
	agency_exp_rel
	agency_exp_fert;
# delimit cr
foreach var in `agency_exp'{
	gen `var'=0
	forvalues j=1/13{
		replace `var'=1 if agency_activity_calc_`j'=="``var''" & (inlist(agency_decider_`j', 1, 2) & male==0) 
		replace `var'=1 if agency_activity_calc_`j'=="``var''" & (inlist(agency_decider_`j', 2) & male==1) | ((inlist(agency_decider_`j', 3) & agency_member_2_`j'=="1" & male==1))
	}
}
lab var agency_exp_childcare "Female HoH Involved in Decisions About Child Care"
lab var agency_exp_health "Female HoH Involved in Decisions About Healthcare"
lab var agency_exp_cook "Female HoH Involved in Decisions About Cooking"
lab var agency_exp_educ "Female HoH Involved in Decisions About Expenditures for Education"
lab var agency_exp_childoth "Female HoH Involved in Decisions About other Expenditures for Children"
lab var agency_exp_food "Female HoH Involved in Decisions About Expenditures for Food Consumption"
lab var agency_exp_rel "Female HoH Involved in Decisions About Religious Expenditures"
lab var agency_exp_fert "Female HoH Involved in Decisions About Fertility"

// create first index for female agency over expenditure decisions (take sum and then standardize)
// LAKSHMI MAR 2021: (take sum and then standardize WRT full sample mean so that men and women reports are on same scale)
egen agency_exp_index1=rowtotal(`agency_exp')
summarize agency_exp_index1
	local mean_exp=r(mean)
	local sd_exp=r(sd)
gen agency_exp_index11=(agency_exp_index1-`mean_exp')/`sd_exp' 

lab var agency_exp_index11 "Index of Female Agency in Expenditure Decisions (Standardized Sum)"
lab var agency_exp_index1 "Index of Female Agency in Expenditure Decisions (0-8)"


/**LAKSHMI MAY 2021: CREATING THE GIVING POWER VS RECEIVING POWER VARIABLES***/
***first putting the man's responses next to the woman's so that comparison is possible
save temp1.dta, replace

use temp1.dta, clear
forvalues j=1/13 {
		gen magency_activity_calc_`j' = agency_activity_calc_`j' if male==1
		gen magency_decider_`j' = agency_decider_`j' if male==1
		gen magency_member_2_`j' = agency_member_2_`j' if male==1

sort hhid male
by hhid: replace magency_activity_calc_`j' = magency_activity_calc_`j'[_n+1] if magency_activity_calc_`j'==""
by hhid: replace magency_decider_`j' = magency_decider_`j'[_n+1] if magency_decider_`j'==.
by hhid: replace magency_member_2_`j' = magency_member_2_`j'[_n+1] if magency_member_2_`j'==""

}

***coding is as follows: https://blogs.worldbank.org/developmenttalk/it-takes-two-womens-empowerment-and-couple-concordance-south-asia
***wife takes power = 1 if wife's response is "myself" & husband's response is anything other than wife; also if wife's response is joint & husband's response is husband/someone else/other
***H gives power = 1 if H response is "wife alone" and W response is not "myself"; also if H response is joint and W is husband/someone else/other
***HW agree if both say wife or both say joint
***all other cases are "W not involved"

local ag_land "Agricultural farming: selling, renting and buying land"
local ag_stock "Livestock raising (i.e. time of buying and selling)"
local ag_gard "Gardening (i.e. choosing crops, planting, deciding how to use the income from gardening)"
local ag_labor "Agricultural farming: hiring labor"
local ag_crops "Agricultural farming: planting decision (i.e. crops choosing)"

local exp_childcare "Child care"
local exp_health "Healthcare"
local exp_cook "Cooking"
local exp_educ "Expenditure for children education"
local exp_childoth "Other expenditure for children"
local exp_food "Expenditure for household's food consumption"
local exp_rel "Religious expenditure (i.e. donation)"
local exp_fert "Fertility decisions"

local aglist ag_land ag_stock ag_gard ag_labor ag_crops

local explist exp_childcare exp_health exp_cook exp_educ exp_childoth exp_food exp_rel exp_fert

foreach var in `aglist' `explist'{
	gen Wtake_`var'=0
	gen Hgive_`var'=0
	gen WHagree_`var' = 0

forvalues i = 1/13 {
	forvalues j = 1/13 {

	**1. Woman takes power variable
	**W reports self and H reports joint
	replace Wtake_`var' = Wtake_`var'+1 if (agency_activity_calc_`i'=="``var''" & magency_activity_calc_`j'=="``var''") & (agency_decider_`i' ==1 & magency_decider_`j' ==2)
	**W reports self and H reports either himself or someone other than wife
	replace Wtake_`var' = Wtake_`var'+1 if (agency_activity_calc_`i'=="``var''" & magency_activity_calc_`j'=="``var''") & (agency_decider_`i' ==1 & magency_decider_`j' ==3 & magency_member_2_`j'=="0")
	replace Wtake_`var' = Wtake_`var'+1 if (agency_activity_calc_`i'=="``var''" & magency_activity_calc_`j'=="``var''") & (agency_decider_`i' ==1 & magency_decider_`j' ==1)
	**W reports joint and H reports himself or someone other than wife
	replace Wtake_`var' = Wtake_`var'+1 if (agency_activity_calc_`i'=="``var''" & magency_activity_calc_`j'=="``var''") & (agency_decider_`i' ==2 & magency_decider_`j' ==1)
	replace Wtake_`var' = Wtake_`var'+1 if (agency_activity_calc_`i'=="``var''" & magency_activity_calc_`j'=="``var''") & (agency_decider_`i' ==2 & magency_decider_`j' ==3 & magency_member_2_`j'=="0")
	
	**2. Husband gives power variable
	**H reports wife alone, W reports anything else
	replace Hgive_`var' = Hgive_`var' + 1 if (agency_activity_calc_`i'=="``var''" & magency_activity_calc_`j'=="``var''") & (inlist(agency_decider_`i', 1,2) & magency_decider_`j' ==3 & magency_member_2_`j'=="1")
	
	**H reports joint, W reports husband/someone else/other
	replace Hgive_`var' = Hgive_`var' + 1 if (agency_activity_calc_`i'=="``var''" & magency_activity_calc_`j'=="``var''") & (agency_decider_`i'==3 & magency_decider_`j' ==2)
	
	**3. H and W agree on decision making authority
	**W and H report wife alone
	replace WHagree_`var' = WHagree_`var' +1 if (agency_activity_calc_`i'=="``var''" & magency_activity_calc_`j'=="``var''") & (agency_decider_`i'==1 & magency_decider_`j' ==3 & magency_member_2_`j'=="1")
	**W and H report joint
	replace WHagree_`var' = WHagree_`var' +1 if (agency_activity_calc_`i'=="``var''" & magency_activity_calc_`j'=="``var''") & (agency_decider_`i'==2 & magency_decider_`j' ==2)
	
	}
}
}

***index of power variables for agriculture and expenditure decisions
egen Wtake_exp_index1=rowtotal(Wtake_exp_*)
egen Wtake_ag_index1 = rowtotal(Wtake_ag_*)

egen Hgive_exp_index1=rowtotal(Hgive_exp_*)
egen Hgive_ag_index1 = rowtotal(Hgive_ag_*)

egen WHagree_exp_index1=rowtotal(WHagree_exp_*)
egen WHagree_ag_index1 = rowtotal(WHagree_ag_*)


***labeling the variables
label var Wtake_exp_index1 "Expenditure decisions index: Woman takes power"
label var Hgive_exp_index1 "Expenditure decisions index: Husband gives power"
label var WHagree_exp_index1 "Expenditure decisions index: Wife and husband agree"

label var Wtake_ag_index1 "Agriculture decisions index: Woman takes power"
label var Hgive_ag_index1 "Agriculture decisions index: Husband gives power"
label var WHagree_ag_index1 "Agriculture decisions index: Wife and husband agree"


*****BEHAVIORAL GAME OUTCOMES
// create willingness-to-pay upper and lower bounds in the cash game
gen wtpcash_lb=""
gen wtpcash_ub=""
replace wtpcash_lb="2750" if bg_cash_2==1
replace wtpcash_ub="3000" if bg_cash_2==1
replace wtpcash_lb="3000" if bg_cash_3==1
replace wtpcash_ub="3750" if bg_cash_3==1
replace wtpcash_lb="3750" if bg_cash_3==2
replace wtpcash_ub=">3750" if bg_cash_3==2
replace wtpcash_lb="700" if bg_cash_5==1 & bg_cash_12==.
replace wtpcash_ub="1700" if bg_cash_5==1 & bg_cash_12==.
* above to correct error when a loop is not followed for 24 people
replace wtpcash_lb="1700" if bg_cash_6==2
replace wtpcash_ub="2250" if bg_cash_6==2
replace wtpcash_lb="1700" if bg_cash_7==1
replace wtpcash_ub="1900" if bg_cash_7==1
* above ignores option 14 which is the same as option 7
replace wtpcash_lb="<200" if bg_cash_8==1
replace wtpcash_ub="200" if bg_cash_8==1
replace wtpcash_lb="200" if bg_cash_9==2
replace wtpcash_ub="450" if bg_cash_9==2
replace wtpcash_lb="200" if bg_cash_10==1
replace wtpcash_ub="300" if bg_cash_10==1
replace wtpcash_lb="300" if bg_cash_10==2
replace wtpcash_ub="450" if bg_cash_10==2
replace wtpcash_lb="1900" if bg_cash_11==1
replace wtpcash_ub="2100" if bg_cash_11==1
replace wtpcash_lb="2100" if bg_cash_11==2
replace wtpcash_ub="2250" if bg_cash_11==2
replace wtpcash_lb="1200" if bg_cash_12==2
replace wtpcash_ub="1700" if bg_cash_12==2
replace wtpcash_lb="700" if bg_cash_13==1
replace wtpcash_ub="1000" if bg_cash_13==1
replace wtpcash_lb="1000" if bg_cash_13==2
replace wtpcash_ub="1200" if bg_cash_13==2
* ignore option 14 cos it is the same as option 7
* same coding for those who were asked Behavioral Game after Trust questions
replace wtpcash_lb="2750" if r2_bg_cash_2==1
replace wtpcash_ub="3000" if r2_bg_cash_2==1
replace wtpcash_lb="3000" if r2_bg_cash_3==1
replace wtpcash_ub="3750" if r2_bg_cash_3==1
replace wtpcash_lb="3750" if r2_bg_cash_3==2
replace wtpcash_ub=">3750" if r2_bg_cash_3==2
replace wtpcash_lb="700" if r2_bg_cash_5==1 & r2_bg_cash_12==.
replace wtpcash_ub="1700" if r2_bg_cash_5==1 & r2_bg_cash_12==.
* above to correct error when a loop is not followed for 26 people
replace wtpcash_lb="1700" if r2_bg_cash_6==2
replace wtpcash_ub="2250" if r2_bg_cash_6==2
replace wtpcash_lb="1700" if r2_bg_cash_7==1
replace wtpcash_ub="1900" if r2_bg_cash_7==1
* above ignores option 14 which is the same as option 7
replace wtpcash_lb="<200" if r2_bg_cash_8==1
replace wtpcash_ub="200" if r2_bg_cash_8==1
replace wtpcash_lb="200" if r2_bg_cash_9==2
replace wtpcash_ub="450" if r2_bg_cash_9==2
replace wtpcash_lb="200" if r2_bg_cash_10==1
replace wtpcash_ub="300" if r2_bg_cash_10==1
replace wtpcash_lb="300" if r2_bg_cash_10==2
replace wtpcash_ub="450" if r2_bg_cash_10==2
replace wtpcash_lb="1900" if r2_bg_cash_11==1
replace wtpcash_ub="2100" if r2_bg_cash_11==1
replace wtpcash_lb="2100" if r2_bg_cash_11==2
replace wtpcash_ub="2250" if r2_bg_cash_11==2
replace wtpcash_lb="1200" if r2_bg_cash_12==2
replace wtpcash_ub="1700" if r2_bg_cash_12==2
replace wtpcash_lb="700" if r2_bg_cash_13==1
replace wtpcash_ub="1000" if r2_bg_cash_13==1
replace wtpcash_lb="1000" if r2_bg_cash_13==2
replace wtpcash_ub="1200" if r2_bg_cash_13==2
* ignore option 14 cos it is the same as option 7
replace wtpcash_lb=".n" if male==1
replace wtpcash_ub=".n" if male==1
lab var wtpcash_lb "Amount Willing to Accept for Autonomy in Cash Game (Min)"
lab var wtpcash_ub "Amount Willing to Accept for Autonomy in Cash Game (Max)"
* de-string lower and upper bound vars
replace wtpcash_lb="200" if wtpcash_lb=="<200"
replace wtpcash_ub="3750" if wtpcash_ub==">3750"
destring wtpcash_lb, replace
destring wtpcash_ub, replace


// create willingness-to-pay upper and lower bounds in the land game
gen wtpland_lb=""
gen wtpland_ub=""
replace wtpland_lb="5.5" if bg_land_2==1
replace wtpland_ub="6" if bg_land_2==1
replace wtpland_lb="6" if bg_land_3==1
replace wtpland_ub="6.5" if bg_land_3==1
replace wtpland_lb="6.5" if bg_land_3==2
replace wtpland_ub=">6.5" if bg_land_3==2
replace wtpland_lb="1.5" if bg_land_5==1 & bg_land_12==.
replace wtpland_ub="3.5" if bg_land_5==1 & bg_land_12==.
* above is to correct a mistake cos the loop was mistakenly not followed for 13 people
replace wtpland_lb="3.5" if bg_land_6==2
replace wtpland_ub="4.5" if bg_land_6==2
replace wtpland_lb="3.5" if bg_land_7==1
replace wtpland_ub="4" if bg_land_7==1
* above ignores option 14 cos it is the same as option 7
replace wtpland_lb="4" if bg_land_7==2 & bg_land_11==.
replace wtpland_ub="4.5" if bg_land_7==2 & bg_land_11==.
* above is to correct a mistake cos the loop was not followed for 5 people
replace wtpland_lb="<0.3" if bg_land_8==1
replace wtpland_ub="0.3" if bg_land_8==1
replace wtpland_lb="0.3" if bg_land_9==1
replace wtpland_ub="1" if bg_land_9==1
* above ignores option 10 cos it is the same as option 2
replace wtpland_lb="1" if bg_land_9==2
replace wtpland_ub="1.5" if bg_land_9==2
replace wtpland_lb="4" if bg_land_11==1
replace wtpland_ub="4.2" if bg_land_11==1
replace wtpland_lb="4.2" if bg_land_11==2
replace wtpland_ub="4.5" if bg_land_11==2
replace wtpland_lb="2.5" if bg_land_12==2
replace wtpland_ub="3.5" if bg_land_12==2
replace wtpland_lb="1.5" if bg_land_13==1
replace wtpland_ub="2" if bg_land_13==1
replace wtpland_lb="2" if bg_land_13==2
replace wtpland_ub="2.5" if bg_land_13==2
* ignoring bg_land_14 variable since it is wrongly coded
* similar code for 2nd round folks
replace wtpland_lb="5.5" if r2_bg_land_2==1
replace wtpland_ub="6" if r2_bg_land_2==1
replace wtpland_lb="6" if r2_bg_land_3==1
replace wtpland_ub="6.5" if r2_bg_land_3==1
replace wtpland_lb="6.5" if r2_bg_land_3==2
replace wtpland_ub=">6.5" if r2_bg_land_3==2
replace wtpland_lb="1.5" if r2_bg_land_5==1 & r2_bg_land_12==.
replace wtpland_ub="3.5" if r2_bg_land_5==1 & r2_bg_land_12==.
* above is a mistake cos the loop was not followed for 12 people
replace wtpland_lb="3.5" if r2_bg_land_6==2
replace wtpland_ub="4.5" if r2_bg_land_6==2
replace wtpland_lb="3.5" if r2_bg_land_7==1
replace wtpland_ub="4" if r2_bg_land_7==1
* above ignores option 14 cos it is the same as option 7
replace wtpland_lb="4" if r2_bg_land_7==2 & r2_bg_land_11==.
replace wtpland_ub="4.5" if r2_bg_land_7==2 & r2_bg_land_11==.
* above is to correct a mistake cos the loop was not followed for 5 people
replace wtpland_lb="<0.3" if r2_bg_land_8==1
replace wtpland_ub="0.3" if r2_bg_land_8==1
replace wtpland_lb="0.3" if r2_bg_land_9==1
replace wtpland_ub="1" if r2_bg_land_9==1
* above ignores option 10 cos it is the same as option 2
replace wtpland_lb="1" if r2_bg_land_9==2
replace wtpland_ub="1.5" if r2_bg_land_9==2
replace wtpland_lb="4" if r2_bg_land_11==1
replace wtpland_ub="4.2" if r2_bg_land_11==1
replace wtpland_lb="4.2" if r2_bg_land_11==2
replace wtpland_ub="4.5" if r2_bg_land_11==2
replace wtpland_lb="2.5" if r2_bg_land_12==2
replace wtpland_ub="3.5" if r2_bg_land_12==2
replace wtpland_lb="1.5" if r2_bg_land_13==1
replace wtpland_ub="2" if r2_bg_land_13==1
replace wtpland_lb="2" if r2_bg_land_13==2
replace wtpland_ub="2.5" if r2_bg_land_13==2
* ignoring bg_land_14 variable since it is wrongly coded
replace wtpland_lb=".n" if male==1
replace wtpland_ub=".n" if male==1
lab var wtpland_lb "Amount Willing to Accept for Autonomy in Land Game (Min)"
lab var wtpland_ub "Amount Willing to Accept for Autonomy in Land Game (Max)"
* de-string lower and upper bound vars
replace wtpland_lb="0.3" if wtpland_lb=="<0.3"
replace wtpland_ub="6.5" if wtpland_ub==">6.5"
destring wtpland_lb, replace
destring wtpland_ub, replace

// This is the list of all variables we will keep for the clean dataset
# delimit ;
local keep
	gov_role_women
	demo_satisfy
	nplot
	form7_tot
	hhid
	vt
	gov_vtaself
	gov_couple_decision
	bothreportland
	land_cat
	riceinc_fem
	demo_condition
	vote_national
	riceinc
	WHagree_ag_index1
	Wtake_exp_index1
	Hgive_exp_index1
	WHagree_exp_index1
	poliknow_minister_correct
	poliknow_vta_correct
	Hgive_ag_index1
	Wtake_ag_index1
	agency_exp_index11
	agency_ag_index11
	riceinc_fem_ln
	individual_id
	male
	age
	educ1
	educ2
	educ3
	hh_size
	land_yn
	landsize
	form7_fem
	form7_femhoh
	form7_femhoh_nomale
	loan_num
	loan_num_fem
	loan_num_male
	aginc_fem
	aginc_fem_ln
	aginc
	nonaginc_fem
	nonaginc_fem_ln
	agency_ag_land
	agency_ag_stock
	agency_ag_gard
	agency_ag_labor
	agency_ag_crops
	agency_ag_index1
	agency_exp_childcare
	agency_exp_health
	agency_exp_cook
	agency_exp_educ
	agency_exp_childoth
	agency_exp_food
	agency_exp_rel
	agency_exp_fert
	agency_exp_index1
	wtpcash_lb
	wtpcash_ub
	wtpland_lb
	wtpland_ub;
# delimit cr

// Keep only needed variables
keep `keep'

* final variable labels
label var vt "Village Tract"
label var gov_vtaself "Respondent Type for Local Leader Survey"
label var male "Respondent is Male"
label var gov_couple_decision "Is it right for women to make decisions about her household's farmland?"
label var gov_role_women "Is it your responsibility to help more women in your village gain land tenure?"
label var poliknow_minister_correct "Did the respondent correctly name the Chief Minister of Ayeyarwaddy?"
label var poliknow_vta_correct "Did the respondent correctly name the Village Tract Administrator?"
label var demo_condition "Preference for Democracy"
label var demo_satisfy "Satisfaction with Democracy in Myanmar"
label var vote_national "Respondent plans to vote in upcoming election"

save "$clean/regfile_May2021", replace
erase temp1.dta